package com.sxc.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/ser02")
public class servlet02 extends HttpServlet {

    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 系统方法，服务器自动调用，只执行一次
     * @throws ServletException
     */
    @Override
    public void init() throws ServletException {
        System.out.println("Servlet被创建了..." + formatter.format(new Date(System.currentTimeMillis())));
    }

    /**
     * 每次调用都会执行
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Servlet被调用了..." + formatter.format(new Date(System.currentTimeMillis())));
    }

    /**
     * 系统方法，服务器自动调用，只执行一次
     */
    @Override
    public void destroy() {
        System.out.println("Servlet被销毁了..." + formatter.format(new Date(System.currentTimeMillis())));
    }
}
